package cn.edu.scau.cmi.wujiaxian.client;

import java.io.IOException;
import java.time.LocalTime;

import cn.edu.scau.cmi.wujiaxian.singleton.Chairman;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SingletonClient extends Application {

	/**
	 * 开始方法
	 */
   @Override
   public void start(Stage primaryStage) {
	   VBox root = new VBox(10);
       singleton(root);
       
       Scene scene = new Scene(root, 700, 1000);
       primaryStage.setTitle("单例模式实验");
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   /**
    * 单例模式的实验
    * @param pane
    */
   public void singleton(Pane pane) {
	   Text title = new Text("单例模式测试");
	   pane.getChildren().add(title);
	   
	   Button btn = new Button();
       btn.setText("生成主席");
       pane.getChildren().add(btn);
       
       Text text = new Text();
       text.setText(LocalTime.now() + ":" + Chairman.getInstance("毛泽东").toString());
       pane.getChildren().add(text);
       btn.setOnAction(event -> {
        	   Text t = new Text();
        	   t.setText(LocalTime.now() + ":" + Chairman.getInstance("毛泽东").toString());
        	   pane.getChildren().add(t);
       });
   }
   
   public static void main(String[] args) {
//       launch(args);
       Platform.runLater(new Runnable() {
           public void run() {             
               new SingletonClient().start(new Stage());
           }
        });
   }
}